package hotel.switchs.oversea.biz.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import hotel.base.oversea.constant.*;
import hotel.base.oversea.constant.enums.CommonEnums;
import hotel.base.oversea.constant.enums.CompareRequestUrlEnums;
import hotel.base.oversea.constant.enums.MtRequestUrlEnums;
import hotel.base.oversea.constant.enums.SwitchChannelEnums;
import hotel.base.oversea.dto.meituan.MtHotelGoodsDto;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.Result;
import hotel.base.oversea.utils.StringUtil;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsInventoryVo;
import hotel.switchs.oversea.api.VO.request.GetdlthotellistVo;
import hotel.switchs.oversea.api.VO.request.SupplierTimeSaleInfoVo;
import hotel.switchs.oversea.api.entity.*;
import hotel.switchs.oversea.biz.config.service.RedisService;
import hotel.switchs.oversea.biz.mapper.*;
import hotel.switchs.oversea.biz.service.SwitchBasicRoomTypeService;
import hotel.switchs.oversea.biz.service.SwitchCreateSubHotelService;
import hotel.switchs.oversea.biz.service.SwitchSubHotelInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.mapper.entity.Example;

import java.util.*;


/**
 * 已创建子酒店
 * @author Zhang·JZ
 * @date 2020-05-28
 */
@Slf4j
@Service
public class SwitchCreateSubHotelServiceImpl extends BaseServiceImpl<SwitchCreateSubHotelEntity> implements SwitchCreateSubHotelService {

    @Autowired
    private SwitchRestTempaleUtilsService switchRestTempaleUtilsService;

    @Autowired
    private RedisService redisService;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private RedisTemplate redisTemplate;


    //子酒店相关接口
    @Autowired
    private SwitchSubHotelInfoService switchSubHotelInfoService;

    @Autowired
    private SwitchCreateSubHotelMapper switchCreateSubHotelMapper;

    @Autowired
    private SwitchMasterHotelInfoMapper switchMasterHotelInfoMapper;

    @Autowired
    private SwitchCreateSubHotelLogMapper switchCreateSubHotelLogMapper;

    @Autowired
    private SwitchHotelUpMapper switchHotelUpMapper;
    @Autowired
    private SwitchHotelUpLogMapper switchHotelUpLogMapper;
    //存储类型为redisKey,
    private Map<String, SwitchCreateSubHotelEntity> masterSubMap = new HashMap<>();

    @Autowired
    SwitchBasicRoomTypeService switchBasicRoomTypeService;


    /**
     * 酒店上架前的效验 是否可以进行创建子酒店
     * 1.要有产品列表数据的酒店才能进行创建
     * 2.地区：福建省(province=19)    星级 4星  10间  50
     * 3.地区：福州      星级3星  数量 10间 10  间
     */
    public boolean isCanCreateSub(String masterHotelId, SwitchMasterHotelInfo switchMasterHotelInfo){
        log.info("==================创建子酒店，进入方法，isCanCreateSub：{}，{}",masterHotelId, JSON.toJSONString(switchMasterHotelInfo));
//        access_token = HttpClientBaseAuth.getAuthToken();
        //获取配置
/*        SwitchHotelOnlineSetEntity switchHotelOnlineSetEntity=new SwitchHotelOnlineSetEntity();
        switchHotelOnlineSetEntity.setProvinceId(switchMasterHotelInfo.getProvinceId());
        List<SwitchHotelOnlineSetEntity> switchHotelOnlineSetEntities=switchHotelOnlineSetMapper.select(switchHotelOnlineSetEntity);
        if(ObjectUtils.isEmpty(switchHotelOnlineSetEntities)||switchHotelOnlineSetEntities.size()<1){
            return false;
        }

        int count=0;
        tab:for(SwitchHotelOnlineSetEntity hotelOnlineSetEntity:switchHotelOnlineSetEntities){
            //按照条件来上传
            if(ObjectUtils.isEmpty(hotelOnlineSetEntity.getIds())||hotelOnlineSetEntity.getSold()==0){
                if(switchMasterHotelInfo.getHotelStar()>=hotelOnlineSetEntity.getMinStar()&&switchMasterHotelInfo.getHotelStar()<=hotelOnlineSetEntity.getMaxStar()){
                    int num=0;
                    if(StringUtils.isEmpty(hotelOnlineSetEntity.getCityName())){
                        num=switchCreateSubHotelLogMapper.getNumByProvinceIdAndStar(hotelOnlineSetEntity.getProvinceId(),hotelOnlineSetEntity.getMinStar(),hotelOnlineSetEntity.getDay());
                    }else{
                        num=switchCreateSubHotelLogMapper.getNumByCityNameAndStar(hotelOnlineSetEntity.getCityName(),hotelOnlineSetEntity.getMinStar(),hotelOnlineSetEntity.getDay());
                    }
                    if(num>=hotelOnlineSetEntity.getNum()){
                        count++;
                    }
                }else{
                    count++;
                    continue tab;
                }
            }else{//按照酒店id来
                log.info("==================酒店的id为{},sold的值为{}",masterHotelId,hotelOnlineSetEntity.getSold());
                if(hotelOnlineSetEntity.getIds().contains(masterHotelId)){
                    return true;
                }else{
                    count++;
                    continue tab;
                }
            }
        }
        //如果没有合适的规则就直接不上架
        if(count==switchHotelOnlineSetEntities.size()){
            log.info("===============================该酒店没有满足上架的配置规则=================================");
            return false;
        }*/
        //先获取美团的id
        String mtHotelId="";
        Map<Integer,String> map=new HashMap<>();
        if(redisService.exists(CommonConstants.SW_HOTEL_AND_MT_HOTEL)){
            map= (Map<Integer, String>) redisService.get(CommonConstants.SW_HOTEL_AND_MT_HOTEL);
        }
        //直接从缓存中读取对应的美团信息
        if(map.containsKey(Integer.valueOf(masterHotelId))){
            log.info("==========美团的酒店id为  从缓存读取===========");
            mtHotelId=map.get(Integer.valueOf(masterHotelId));
        }else{//从接口读取
            log.info("==========美团的酒店id为  从接口读取===========");
            Map<String,String> params=new HashMap<>();
            params.put("masterHotelId",masterHotelId);
            String url= CommonUrlConstants.COMPARE_HOST+"/"+ CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();//+"?access_token="+access_token;
            Result result;
            try {
                result= switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url,params);
                if(result.getCode()==CommonConstants.SUCCESS){
                    mtHotelId=result.getData().toString();
                    log.info("==========美团的酒店id为============{}",mtHotelId);
                }else{
                    log.info("==========美团的酒店id为  return false============{}，{}", JSON.toJSONString(result),masterHotelId);
                    return false;
                }
            }catch (Exception e){
                log.info("=======获取美团酒店id出现异常==============");
                return false;
            }
        }
        if(ObjectUtils.isEmpty(mtHotelId)){
            log.info("=======获取美团酒店id为null=============={}",masterHotelId);
            return false;
        }
        //2.调用美团的产品列表
        String url=CommonUrlConstants.MEITUAN_HOST+ "/"+MtRequestUrlEnums.GET_MT_GOODS_BY_HOTEL_ID.getUrl();//+"?access_token="+access_token;
        Map<String,Integer> params=new HashMap<>();
        params.put("hotelId",Integer.valueOf(mtHotelId));
        Map<String, List<MtHotelGoodsDto>> goodsMap;
        Result result;
        try{
            result=switchRestTempaleUtilsService.sendPostRequest(url,params);
            if(result.getCode()!= CommonConstants.SUCCESS){
                log.info("==========获取美团的产品列表数据失败=============");
                result=switchRestTempaleUtilsService.sendPostRequest(url,params);
                if(result.getCode()!= CommonConstants.SUCCESS){
                    log.info("==========获取美团的产品列表数据失败============={}", JSON.toJSONString(result));
                    return false;
                }else{
                    if(!ObjectUtils.isEmpty(result.getData())){
                        goodsMap= (Map<String, List<MtHotelGoodsDto>>) result.getData();
                    }else{
                        log.info("==========获取美团的产品列表数据失败============={}", JSON.toJSONString(result));
                        return  false;
                    }
                }
            }else{
                if(!ObjectUtils.isEmpty(result.getData())){
                    goodsMap= (Map<String, List<MtHotelGoodsDto>>) result.getData();
                }else{
                    log.info("==========获取美团的产品列表数据失败============={}", JSON.toJSONString(result));
                    return  false;
                }
            }
        }catch (Exception e){
            return  false;
        }
        log.info("=============获取美团的产品数据成功,长度为{}================",goodsMap.size());
        if(goodsMap.size()>0&&goodsMap.keySet().size()>1){
            //判断是否有库存
            for(List<MtHotelGoodsDto> mtHotelGoodsDtos:goodsMap.values()){
                for(MtHotelGoodsDto mtHotelGoodsDto:mtHotelGoodsDtos){
                    Map<String,Object> param=new HashMap<>();
                    param.put("roomId",mtHotelGoodsDto.getMtRoomId());
                    param.put("goodsId",mtHotelGoodsDto.getMtGoodsId());
                    param.put("days",1);
                    MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo=getMtGoodsInventory(param);
                    if(mtHotelGoodsInventoryVo.getRemain()>0){
                        return true;
                    }
                }
            }
            return false;
        }else{
            return false;
        }
    }
    /**
     * 获取美团的库存
     */
    public MtHotelGoodsInventoryVo getMtGoodsInventory(Map<String,Object> params){
//        access_token = HttpClientBaseAuth.getAuthToken();
        MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo=new MtHotelGoodsInventoryVo();
        String url=CommonUrlConstants.MEITUAN_HOST+"/"+MtRequestUrlEnums.GET_MT_GOODS_INVENTORY_BY_DAYS.getUrl();//+"?access_token="+access_token;
        try{
            Result<MtHotelGoodsInventoryVo> result2=switchRestTempaleUtilsService.sendPostRequestGetGoodsInventory(url,params);
            if(result2.getCode()==CommonConstants.SUCCESS){
                mtHotelGoodsInventoryVo=result2.getData();
                log.info("库存返回成功,返回的数据是{}",mtHotelGoodsInventoryVo);
            }else{
                log.info("=======库存返回失败=========,失败原因是{}",result2.getMsg());
            }
        }catch (Exception e){
            log.info("发生的异常为{}",e.getMessage());
        }
        return mtHotelGoodsInventoryVo;
    }


    /**
     * 存储数据
     * @param masterHotelId
     * @return
     */
    @Override
    @Transactional
    public Result<Object> saveSubHotel(String masterHotelId) {
       //1.先获取酒店星级 城市id
        SwitchMasterHotelInfo switchMasterHotelInfo=switchMasterHotelInfoMapper.getMasterInfoByMasterHotelId(masterHotelId);
        if(ObjectUtils.isEmpty(switchMasterHotelInfo)){
            return new Result<>("找不到该酒店信息，无法上架");
        }
        //2.获取携程配置
   /*     SwitchBaseSetEntity switchBaseSetEntity=new SwitchBaseSetEntity();
        if(!ObjectUtils.isEmpty(redisService.get(CommonConstants.SWITCH_BASE_SET))){
            switchBaseSetEntity= (SwitchBaseSetEntity) redisService.get(CommonConstants.SWITCH_BASE_SET);
        }else{
            switchBaseSetEntity.setId(1);
            switchBaseSetEntity=switchBaseSetMapper.selectOne(switchBaseSetEntity);
            redisService.set(CommonConstants.SWITCH_BASE_SET,switchBaseSetEntity);
        }
        if(switchBaseSetEntity.getOpenOnlineSet()==0){
            //3.先判断符合上架规则
            if(!isCanCreateSub(masterHotelId,switchMasterHotelInfo)){
                log.info("=========该酒店不满足上架规则，暂时不上架========");
                return new Result<>("该酒店不满足上架规则，暂时不上架");
            }
        }*/
        //如果酒店已经是黑名单的就重新过滤
        Example example=new Example(SwitchHotelUpEntity.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("masterHotelId",masterHotelId);
        //黑名单的酒店不进行创建,不存在上架表的不创建
        SwitchHotelUpEntity switchHotelUpEntitys=switchHotelUpMapper.selectOneByExample(example);
        if(!ObjectUtil.isEmpty(switchHotelUpEntitys)&&(switchHotelUpEntitys.getStatus()==2||switchHotelUpEntitys.getUp()==2)){
            return new Result<>("黑名单不进行创建");
        }else if(!ObjectUtil.isEmpty(switchHotelUpEntitys)&&(switchHotelUpEntitys.getStatus()==3||switchHotelUpEntitys.getUp()==3)){
            return new Result<>("酒店正则售卖无需重新创建");
        }

        //如果有创建过，重新创建记录
        example=new Example(SwitchCreateSubHotelLogEntity.class);
        criteria=example.createCriteria();
        criteria.andEqualTo("masterHotelId",masterHotelId);
        int count=switchCreateSubHotelLogMapper.selectCountByExample(example);
        if(count>0){
            //删除创建记录
            switchCreateSubHotelLogMapper.deleteByExample(example);
            //删除创建子酒店数据
            example=new Example(SwitchCreateSubHotelEntity.class);
            criteria=example.createCriteria();
            criteria.andEqualTo("masterHotelId",masterHotelId);
            switchCreateSubHotelMapper.deleteByExample(example);
            log.info("=======删除记录重新创建===============");
        }
        log.info(">>>>>调用根据母酒店生成子酒店接口 start<<<<<");
        Result createSubHotelIdResult = (Result) switchSubHotelInfoService.createSubHoltel(new Integer[]{Integer.valueOf(masterHotelId)});
        //接口调用失败
        if(createSubHotelIdResult.getCode() != CommonConstants.SUCCESS){
            log.info(">>>>调用根据母酒店生成子酒店接口：接口调用失败");
            return createSubHotelIdResult;
        }

        Integer[] subHotelIds = (Integer[])createSubHotelIdResult.getData();
        if(subHotelIds.length == 0){
            log.info(">>>>调用根据母酒店生成子酒店接口：返回子酒店数据为空");
            return new Result<>(CommonEnums.DATA_NULL.getCode(), "返回子酒店数据为空"+CommonEnums.DATA_NULL.getMsg());
        }
        //获取子酒店id
        Integer subHotelId = subHotelIds[0];
        //删除上架数据,重新创建
        example=new Example(SwitchHotelUpEntity.class);
        criteria=example.createCriteria();
        criteria.andEqualTo("hotelId",subHotelId);
        count=switchHotelUpMapper.selectCountByExample(example);
        if(count>0){
            switchHotelUpMapper.deleteByExample(example);
        }
        //拼接成对应redisKey
        String redisKey = masterHotelId+"-"+String.valueOf(subHotelId);

        //缓存了新创建的子酒店id，后续拉取物理房型定时器和拉取静态物理房型定时器只针对新创建的子酒店而不重复拉取所有历史子酒店
        redisTemplate.opsForList().leftPush(SwitchConstants.CREATE_SUB_FOR_ROOM_MASTER_JOB,String.valueOf(subHotelId));
        log.info("创建子酒店 SwitchConstants.CREATE_SUB_FOR_ROOM_MASTER_JOB.size={},{}",redisTemplate.opsForList().size(SwitchConstants.CREATE_SUB_FOR_ROOM_MASTER_JOB),String.valueOf(subHotelId));
        redisTemplate.opsForList().leftPush(SwitchConstants.CREATE_SUB_FOR_ROOM_STATIC_JOB,masterHotelId+"_"+subHotelId);
        log.info("创建子酒店 SwitchConstants.CREATE_SUB_FOR_ROOM_STATIC_JOB.size={},{}",redisTemplate.opsForList().size(SwitchConstants.CREATE_SUB_FOR_ROOM_STATIC_JOB),masterHotelId+"_"+subHotelId);

        //判断redis中是否存在(redis，数据库同步)
     /*   if(redisService.exists(CommonBaseConstants.REDIS_DB_0,SwitchConstants.REDIS_SWITCH_HOTEL_MASTER_SUB_IDS)){
            masterSubMap = (Map<String, SwitchCreateSubHotelEntity>) redisService.get(SwitchConstants.REDIS_SWITCH_HOTEL_MASTER_SUB_IDS);
            if(masterSubMap.containsKey(redisKey)){
                return updateSubHotel(Integer.valueOf(masterHotelId),subHotelId);
            }
        }*/
        //初始化 SwitchCreateSubHotelEntity
        SwitchCreateSubHotelEntity switchCreateSubHotel = new SwitchCreateSubHotelEntity();
        switchCreateSubHotel.setId(StringUtil.getUUID());
        switchCreateSubHotel.setState(0);//系统状态   0:正常   1:异常
        switchCreateSubHotel.setRemark("");
        switchCreateSubHotel.setCreateTime(new Date());
        switchCreateSubHotel.setModifyTime(new Date());
        switchCreateSubHotel.setMasterHotelId(Integer.valueOf(masterHotelId));
        switchCreateSubHotel.setSubHotelId(subHotelId);

        //记录创建记录
        SwitchCreateSubHotelLogEntity switchCreateSubHotelLogEntity=new SwitchCreateSubHotelLogEntity();
        switchCreateSubHotelLogEntity.setCreateTime(new Date());
        switchCreateSubHotelLogEntity.setCityName(switchMasterHotelInfo.getCityName());
        switchCreateSubHotelLogEntity.setProvinceId(switchMasterHotelInfo.getProvinceId());
        switchCreateSubHotelLogEntity.setMasterHotelId(Integer.valueOf(masterHotelId));
        switchCreateSubHotelLogEntity.setHotelStar(switchMasterHotelInfo.getHotelStar());

        //直接放入上架表中
        SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
        switchHotelUpEntity.setCreateTime(new Date());
        switchHotelUpEntity.setHotelId(subHotelId);
        int up=1;
        if(redisService.exists("switch_create_stu_hotel_control_up")){
            Integer isUp= (Integer) redisService.get("switch_create_stu_hotel_control_up");
            if(!ObjectUtils.isEmpty(isUp)&&isUp==1){
                up=3;
            }
        }
        switchHotelUpEntity.setUp(up);
        switchHotelUpEntity.setStatus(up);
        switchHotelUpEntity.setMasterHotelId(Integer.valueOf(masterHotelId));
        String hotelName=switchMasterHotelInfoMapper.selectHotelNameByHotelId(Integer.valueOf(masterHotelId));
        switchHotelUpEntity.setHotelName(hotelName);
        switchHotelUpEntity.setId(StringUtil.getUUID());
        switchHotelUpEntity.setRemark("");
        switchHotelUpMapper.insert(switchHotelUpEntity);
        //记录到上架记录中
        SwitchHotelUpLogEntity switchHotelUpLogEntity=new SwitchHotelUpLogEntity();
        switchHotelUpLogEntity.setCreateTime(new Date());
        switchHotelUpLogEntity.setGenre(0);
        switchHotelUpLogEntity.setHotelId(subHotelId);
        switchHotelUpLogEntity.setUp(up);
        switchHotelUpLogEntity.setUsername("system-创建子酒店");
        switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
        log.info("switchCreateSubHotel{}",switchCreateSubHotel);
        redisService.remove("goods_query_job_up_hotel_data");
        String mtHotelId="";
        try{
            switchCreateSubHotelMapper.insert(switchCreateSubHotel);
            switchCreateSubHotelLogMapper.insert(switchCreateSubHotelLogEntity);
            //先获取美团的id
            Map<String,String> params=new HashMap<>();
            params.put("masterHotelId",masterHotelId);
            String url= CommonUrlConstants.COMPARE_HOST+"/"+ CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
            Result result;
            try {
                result= switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url,params);
                if(result.getCode()==CommonConstants.SUCCESS){
                    mtHotelId=result.getData().toString();
                    log.info("==========美团的酒店id为============{}",mtHotelId);
                    redisService.set(MeituanConstants.REIDS_MAP_ALL_SALE_HOTEL_IDS+mtHotelId,1);
                }else{
                    log.info("==========美团的酒店id为  return false============{}，{}", JSON.toJSONString(result),masterHotelId);
                }
            }catch (Exception e){
                log.info("=======获取美团酒店id出现异常==============");
            }
        }catch (Exception e){
            log.error(e.getMessage());
            return new Result<>(CommonEnums.PARAM_ERROR);
        }

        //存入redis
        masterSubMap.put(redisKey,switchCreateSubHotel);

        log.info(">>>>>保存缓存数据完成<<<<<");

        log.info(">>>>>调用根据母酒店生成子酒店接口 end<<<<<");
        Result<Object> result=updateSubHotel(Integer.parseInt(masterHotelId),subHotelId);
        //拉取母物理房型
        result=switchBasicRoomTypeService.getHotelBasicRoomList(subHotelId);
        if(result.getCode()==CommonConstants.SUCCESS){
            //调用美团接口进行房型匹配
            String url=CommonUrlConstants.COMPARE_HOST+CompareRequestUrlEnums.COMPARE_HOTEL_ROOM_BY_HOTEL_ID_SQL.getUrl();
            Map<String,Integer> params=new HashMap<>();
            params.put("mtHotelId",Integer.valueOf(mtHotelId));
            params.put("line",2);
            switchRestTempaleUtilsService.sendPostRequestToCompareToCompareHotelRoomId(url,params);
        }

        return new Result<>();
    }



    /*@Override
    public Result saveSubHotelAndGetSubInfo(String masterHotelId) {
        Result result = this.saveSubHotel(masterHotelId);
        if(null != result && result.getCode() == CommonConstants.SUCCESS && null != result.getData()){
            Integer subHotelId = (Integer)result.getData();
            Map<String,Object> params = new HashMap();
            params.put("masterHotelID",masterHotelId);
            params.put("hotelID",subHotelId);
            params.put("pageIndex",1);
            params.put("pageSize",1);
            Result<Object> subHotelResult = switchSubHotelInfoService.getStuHotelList(1,1,params);
            GetDltHotelListVo getDltHotelListVo = (GetDltHotelListVo)subHotelResult.getData();
            if(null != getDltHotelListVo){
                List<DltHotelEntityVo> dltHotelEntityVos = getDltHotelListVo.getDltHotelEntityList();
                switchSubHotelInfoService.saveHotelInfoOne(dltHotelEntityVos);
            }
            return new Result();
        }else{
            if(result.getCode() != CommonConstants.SUCCESS){
                return result;
            }
            return new Result(CommonConstants.REQUEST_ERROR,"创建失败");
        }
    }*/

    /**
     * 根据子酒店id更新属性数据
     * @param masterHotelId 母酒店
     * @param subHotelId 子酒店
     * @return
     */
    public Result<Object> updateSubHotel(int masterHotelId,int subHotelId) {


        log.info(">>>>进入根据酒店id更新相关属性数据");
        /************根据子酒店id 调用获取子酒店接口信息 start************/
        log.info(">>>>根据子酒店id 调用获取子酒店接口信息 start");
        Result<Object> stuHotelListResult = null;
        //判断redis中是否存在相关数据
        Map subHotelMap = new HashMap();
        if(redisService.exists(SwitchConstants.REDIS_SWITCH_HOTEL_MASTER_SUB_IDS)){
            subHotelMap = (Map) redisService.get(SwitchConstants.REDIS_SWITCH_HOTEL_MASTER_SUB_IDS);
            //如果接口已调用过，则直接执行
            if(!subHotelMap.containsKey(String.valueOf(subHotelId))){
                stuHotelListResult = getSubHotel(subHotelId);
            }
        }else{
            stuHotelListResult = getSubHotel(subHotelId);
        }
        //接口调用失败
        if(!ObjectUtils.isEmpty(stuHotelListResult) && (stuHotelListResult.getCode() != CommonConstants.SUCCESS)){
            log.info(">>>>根据子酒店id 调用获取子酒店接口信息：接口调用失败");
            return stuHotelListResult;
        }
        log.info(">>>>根据子酒店id 调用获取子酒店接口信息 end");
        /************根据子酒店id 调用获取子酒店接口信息 end************/

        /************设置子酒店售卖状态 start************/
        log.info(">>>>设置子酒店售卖状态 start");
        Map<String, Object> updateChannelVoMap = new HashMap<>();
        updateChannelVoMap.put("hotelIDs", new int[]{subHotelId});
        int up=1;
        if(redisService.exists("switch_create_stu_hotel_control_up")){
            int isUp= (int) redisService.get("switch_create_stu_hotel_control_up");
            if(isUp==1){
                updateChannelVoMap.put("cBookable", SwitchChannelEnums.SALE.getCode());//默认停售
            }else{
                updateChannelVoMap.put("cBookable", SwitchChannelEnums.DOWN.getCode());//默认停售
            }
        }else{
            updateChannelVoMap.put("cBookable", SwitchChannelEnums.DOWN.getCode());//默认停售
        }
        updateChannelVoMap.put("qBookable", SwitchChannelEnums.SALE.getCode());//默认停售
        updateChannelVoMap.put("channelABookable", SwitchChannelEnums.SALE.getCode());//默认停售
        updateChannelVoMap.put("b2bBookable", SwitchChannelEnums.SALE.getCode());//默认停售

        log.info(">>>>updateChannelVoMap{}",updateChannelVoMap);
        Result<Object> setHotelSupplierBookableResult = switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());

        //接口调用失败
        if(setHotelSupplierBookableResult.getCode() != CommonConstants.SUCCESS){
            log.info(">>>>设置子酒店售卖状态：接口调用失败");
            return setHotelSupplierBookableResult;
        }
        log.info(">>>>设置子酒店售卖状态 end");
        /************设置子酒店售卖状态 end************/


        /************设置子酒店最晚预订时间,先获取美团相关接口信息，根据美团相关时间设定 start 暂时不做预定时间设置************/
//        log.info(">>>>设置子酒店最晚预订时间,先获取美团相关接口信息，根据美团相关时间设定 start");
//        Map tempMap = new HashMap();
//        tempMap.put("access_token",access_token);
//        tempMap.put("masterHotelId",masterHotelId);
//        //获取到美团携程酒店校验后的对应酒店id
//        Result meituanResult = restTemplate.getForObject(COMPARE_URI+"/compareHotel/getCompareHotelByMasterHotelId?masterHotelId={masterHotelId}&access_token={access_token}",Result.class,tempMap);
//        Map mtMap = new HashMap();
//        mtMap = (Map) meituanResult.getData();
//        log.info("meituanResult 返回对象{}",mtMap);
//        //获取美团酒店id
//        String meituanHotelId = (String) mtMap.get("mtHotelId");
//        //根据美团酒店id，获取对应的美团酒店最晚预定时间
//
//
//        log.info(">>>>设置子酒店最晚预订时间 end");
        /************设置子酒店最晚预订时间 end************/

        //存入redis
        if(!masterSubMap.isEmpty() && masterSubMap.size()>0){
            redisService.set(SwitchConstants.REDIS_SWITCH_HOTEL_MASTER_SUB_IDS,masterSubMap);
        }

        return new Result<>(subHotelId,"success");
    }


    /**
     * 根据子酒店id 调用获取子酒店接口信息
     * @param subHotelId
     * @return
     */
    public Result<Object> getSubHotel(int subHotelId){
        GetdlthotellistVo getdlthotellistVo = new GetdlthotellistVo();
        getdlthotellistVo.setHotelID(Integer.valueOf(subHotelId));

        log.info(">>>>getdlthotellistVo{}",getdlthotellistVo);
        Map<String,Object> getdlthotellistVoMap=new HashMap<>();
        if(getdlthotellistVo.getHotelID()!=0){
            getdlthotellistVoMap.put("hotelID",getdlthotellistVo.getHotelID());
        }
        log.info(">>>>getdlthotellistVoMap{}",getdlthotellistVoMap);

        Result<Object> stuHotelListResult = switchSubHotelInfoService.getStuHotelList(getdlthotellistVo.getPageSize(),getdlthotellistVo.getPageIndex(),getdlthotellistVoMap);

        return stuHotelListResult;
    }
}
